package com.javashizhan.demo.redissession.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.javashizhan.demo.redissession.common.Constants;

/**
 * 
 * @Description: 登陆类
 *
 * @author 飞流
 * @date 2019年8月11日
 * @知识星球 Java实战营
 * @微信公众号 JAVA栈实战营
 * @站点 http://javashizhan.com/
 *
 */
@Component
@RestController
public class LoginController {

	@RequestMapping("/login")
	public String login(@RequestBody String userId, HttpSession  session) throws Exception {
		session.setAttribute(Constants.SESSION_USER_ID, userId);
		return "Login success.";
	}

	/**
	 * 移除session，方便测试
	 * 
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/removeSession")
	public String removeSession(HttpSession session) throws Exception {
		session.removeAttribute(Constants.SESSION_USER_ID);
		return "Remove session success.";
	}
}
